package cn.ultrarisk.scadmin.manager.scheduler;

import cn.ultrarisk.scadmin.manager.biz.common.context.OperationType;
import cn.ultrarisk.scadmin.manager.biz.common.service.OperationLogService;
import cn.ultrarisk.scadmin.manager.biz.stat.service.SolrNodeStatService;
import cn.ultrarisk.scadmin.manager.biz.stat.service.SolrReplicaStatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * HourStatScheduler
 *
 * @author sevendlong(lin23871@163.com)
 * @date 2014/5/22
 * @since V1.0
 */
@Component
public class HourStatScheduler {
    @Autowired
    private SolrNodeStatService solrNodeStatService;
    @Autowired
    private SolrReplicaStatService solrReplicaStatService;
    @Autowired
    private OperationLogService operationLogService;

    /**
     * 构建上一个小时的node和replica统计数据
     *
     * @throws Exception
     */
    public void execute() throws Exception {
        long time = System.currentTimeMillis() - 3600 * 1000;

        solrNodeStatService.deleteHourStat(time);
        solrNodeStatService.buildHourStat(time);

        solrReplicaStatService.deleteHourStat(time);
        solrReplicaStatService.buildHourStat(time);

        operationLogService.createBuildStatLog(OperationType.BUILD_HOUR_STAT);
    }
}
